
/**
 * 封装swan.request,实现链式调用
 * @param [Object] options
 */
export default function (options) {
  return new Promise(function (resolve, reject) {
    if (options.loading == true) {
      wx.showLoading({ title: '加载中', mask: 'true' });
    }
    wx.request({
      url: options.url || '',
      method: options.method || 'GET',
      dataType: options.dataType || 'json',
      data: options.data || {},
      header: options.header || {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (options.loading == true) {
          wx.hideLoading();
        }
        resolve(res);
      },
      fail: function (err) {
        reject('错误码：' + err.errCode);
      }
    });
  })
}